{include file="public/head" /}
<!--有理想的地方，地狱都是天堂-->
<!--Copyright @ df81.com 版权所有-->
<!--作者: 南国老符 邮箱：1062129401@qq.com-->
        <!-- 左侧菜单 开始 -->
        <div class="sidebar">
            <nav>
                <ul class="nav nav-pills nav-sidebar flex-column nav-flat nav-legacy d-block d-md-none" data-widget="treeview" role="menu" data-accordion="false">
                    {include file="public/left_content" /}
                </ul>
                <ul class="nav nav-pills nav-sidebar flex-column nav-flat nav-legacy d-block d-md-none" data-widget="treeview" role="menu" data-accordion="false">
                    {include file="public/left_data" /}
                </ul>
                <ul class="nav nav-pills nav-sidebar flex-column nav-flat nav-legacy" data-widget="treeview" role="menu" data-accordion="false">
                    {include file="public/left_global" /}
                </ul>
                <ul class="nav nav-pills nav-sidebar flex-column nav-flat nav-legacy d-block d-md-none" data-widget="treeview" role="menu" data-accordion="false">
                    {include file="public/left_system" /}
                </ul>
            </nav>
        </div>
        <!-- 左侧菜单 结束 -->
    </aside>
    <!-- 左侧 结束 -->
    <!-- 右侧 开始 -->
    <div class="content-wrapper">
        <!-- 内容导航 开始 -->
        <div class="content-header py-2 bg-white mb-3">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-sm-12">
                        <ol class="breadcrumb">
                            <li>{:lang('v_global')}<i class="fas fa-angle-right mx-2"></i></li>
                            <li>{:lang('v_system_manage')}<i class="fas fa-angle-right mx-2"></i></li>
                            <li>{:lang('v_data')} {:lang('v_backup')}</li>
                        </ol>
                    </div>
                </div>
            </div>
        </div>
        <!-- 内容导航 结束 -->
        <!-- 内容主体 开始 -->
        <section class="content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-md-12">
                        <div class="card">
                            <div class="card-body">
                                <?php if(PHP_VERSION >= 8){ ?>
                                    <div class="w-100 py-3 text-center h5 text-danger"><i class="fas fa-info-circle mr-1"></i>暂不支持PHP8.0以上版本</div>
                                <?php }else{ ?>
                                    <div class="w-100 mb-3">
                                        <a id="export" class="btn btn-success mb-2" href="{:url('/databackup/export',['lang'=>input('lang')])}"><i class="fa fa-plus-circle"></i> {:lang('v_add')} {:lang('v_backup')}</a>
                                    </div>
                                    <table class="table table-striped table-bordered table-hover">
                                        <form name="form_list" id="form_list" action="" method="post">
                                            <tr>
                                                <th>{:lang('v_document_name')}</th>
                                                <th>{:lang('v_backup')} {:lang('v_time')}</th>
                                                <th class="d-invisible">{:lang('v_document')} {:lang('v_size')}</th>
                                                <th width="300" class="text-center">{:lang('v_do')}</th>
                                            </tr>
                                            {foreach name='list' key='i' item='rs'}
                                                <tr>
                                                    <td>{$rs.time|date='Ymd-His'}-{$rs.part}.sql{eq name="rs.compress" value="GZ"}.gz{/eq}</td>
                                                    <td>{$rs.time|date='Y-m-d H:i:s'}</td>
                                                    <td class="d-invisible">{$rs.size|getfilesize}</td>
                                                    <td class="text-center">
                                                        <a class="btn btn-sm btn-success mb-2 mr-2" href="{:url('/databackup/down',['lang'=>input('lang'),'time'=>$rs['time']])}"><i class="fa fa-fw fa-download mr-1"></i>{:lang('v_load')}</a>
                                                        <a class="btn btn-sm btn-info mb-2 mr-2 dataimport" href="{:url('/databackup/import',['lang'=>input('lang'),'time'=>$rs['time']])}"><i class="fa fa-fw fa-reply-all mr-1"></i>{:lang('v_restore')}</a>
                                                        <span onClick="javascript:do_confirm('','','{:url('/databackup/del',['lang'=>$lang,'time'=>$rs['time']])}','','');" class="btn btn-sm btn-danger mb-2"><i class="fa fa-fw fa-trash mr-1"></i>{:lang('v_delete')}</span>
                                                    </td>
                                                </tr>
                                            {/foreach}
                                        </form>
                                    </table>
                                <?php } ?>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </section>
        <!-- 内容主体 结束 -->
    </div>
    <!-- 右侧 结束 -->
{include file="public/foot" /}
<!--数据库备份 开始-->
<script type="text/javascript">
//备份表方法
$("#export").click(function(){
    $(this).html("{:lang('v_data_require_backup')}");
    $.post(
        $("#export-form").attr("action"),
        $("#export-form").serialize(), 
        function(data){
            if(data.code==1){
                $("#export").html( "{:lang('v_data_begin_donotclose')}");
                backup(data.data.tab);
                window.onbeforeunload = function(){ return "{:lang('v_data_backuping_donotclose')}" }
            }else{
                alert(data.msg);
            }
        }
    , "json");
    $("#export").html("<i class='fa fa-plus-circle'></i> {:lang('v_add')} {:lang('v_backup')}");
    return false;  
}); 
//递归备份表
function backup(tab,status){
    status && showmsg(tab.id, "{:lang('v_data_begin_backup')}(0%)");
    $.get( $("#export-form").attr("action"), tab, function(data){
    // console.log(data)
        if(data.code==1){
            showmsg(tab, data.msg);
            if(!$.isPlainObject(data.data.tab)){
                $("#export").html("{:lang('v_data_end_backup')}");
                window.onbeforeunload = function(){ return null }
                location.reload();
                return;
            } 
            backup(data.data.tab, tab.id != data.data.tab.id);
        }else{
            $("#export").html("{:lang('v_add')} {:lang('v_backup')}");
        }
    }, "json");
}
//修改备份状态
function showmsg(tab, msg){
    $("table tbody tr").eq(tab.id).find(".info").html(msg)
}
</script>
<form id="export-form" method="post" action="{:url('/databackup/export',['lang'=>input('lang')])}">
{foreach name='tablelist' item='table'}   
    <input style="display: none;" checked="chedked" type="checkbox" name="tables[]" value="{$table.name}">
{/foreach}
</form>
<!--数据库备份 结束-->
<!--数据库还原 开始-->
<script type="text/javascript">
$(".dataimport").click(function(){
    var self = this, status = ".";
    $(this).parent().prevAll('.status').html("").html('{:lang('v_data_begin_restore')}');
    $.get(self.href, success, "json");
    // window.onbeforeunload = function(){ return "{:lang('v_data_restoring_donotclose')}" }
    return false;
    function success(data){
        $('#modal_sm_content').removeClass('bg-opacity');
        var html =  modal_head;
            html += '<div class="modal-body py-4 text-center text-md text-success">';
            html +=     data.msg;
            html += '</div>';
        $('#modal_sm_content').html(html);
        if(data.code==1){
            $(self).parent().prev().text(data.msg);
            if(data.data.part){
                $.get(self.href, 
                    {"part" : data.data.part, "start" : data.data.start}, 
                    success, 
                    "json"
                );
            }else{
                $('#modal_sm').modal('show');
                // 关闭小对话框重载网页
                $('body').on('hidden.bs.modal','.modal',function(){
                    window.location.reload();
                });
                close(index);
                // alert(data.msg, function(index){
                //     window.onbeforeunload = function(){
                //         location.reload();
                //     }
                //     close(index);
                // });
            }
        }else{
            $('#modal_sm').modal('show');
        }
    }
});
</script>
<!--数据库还原 结束-->
</body>
</html>